<?php
declare(strict_types=1);

namespace Zms\Request;

use Zms\Request\Driver\Curl;
use Zms\Request\Driver\Swoole;

class Http
{
    /**
     * 以CURL为请求驱动
     */
    const CURL = 'curl';

    /***
     * 以SWOOLE为请求驱动
     */
    const SWOOLE = 'swoole';

    /**
     * @describe 请求方式
     * @user zlf <zms-pro@qq.com> 2025/3/13
     * @return RequestAbstract
     */
    public static function instance($driver = null)
    {
        if (is_null($driver)) {
            if (defined("ZMS_REQUEST_DRIVER")) {
                $driver_name = ZMS_REQUEST_DRIVER;
            } else {
                $driver_name = self::CURL;
            }
        } else {
            if ($driver === self::CURL) {
                $driver_name = self::CURL;
            } else {
                $driver_name = self::SWOOLE;
            }
        }
        if ($driver_name === self::CURL) {
            return new Curl();
        } elseif ($driver_name === self::SWOOLE) {
            return new Swoole();
        }
        throw new \Exception('request driver error');
    }
}